package com.geovis.emergency.spd.handler;

import com.geovis.common.core.api.Result;
import com.geovis.common.core.exception.BizException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
    /**
     * 业务异常处理
     *
     * @param businessException 业务异常信息
     */
    @ExceptionHandler(value = BizException.class)
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public <T> Result<T> businessExceptionHandler(BizException businessException) {
        log.error(businessException.getMessage(), businessException);
        return Result.failed(businessException.getMessage());
    }

    /**
     * 未知异常处理
     *
     * @param exception 异常信息
     */
    @ExceptionHandler(value = Exception.class)
    public <T> Result<T> exceptionHandler(Exception exception) {
        log.error(exception.getMessage(), exception);
        return Result.failed(exception.getMessage());
    }


}
